﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.Model;
using HZ.MBSM.DBUtility;

public partial class Bidder_CompeteGoods : System.Web.UI.Page
{
    int prjid;
    public string status;
    String CP1strConditions;
    Int64 CompetepriceAccountid_TBR;
    private const int GVgoodsid = 0;
    private const int GVpoductname = 1;
    private const int GVMedimite = 2;
    private const int GVoutlookc = 3;
    private const int GVcompanyname = 4;
    private const int GVfactor = 5;
    private const int GVspprice = 6;
    // private const int GVlimitprice=7;
    private const int GVCompetePackPrice1 = 7;
    private const int GVCompetePackPrice2 = 8;
    private const int GVCompetePackPrice3 = 9;
    private const int GVCompetitionSwich = 10;
    private const int GVCompeteNum = 11;
    private const int GVCompetePackPrice1V = 12;
    private const int GVCompetePackPrice2V = 13;
    private const int GVbidid = 14;
    private const int CompeteMinPrice1 = 15;      //最小制剂报价

    private const int CompeteMinPrice2 = 16;
    private const int GVbidCount = 17;               //竞价投标人数
    private const int GVAlreadyIsbidNum = 18;  //该竞价组已中标数
    private const int GVshouldisbidnum = 19;     //应该中标数

    private const int GVlessnum = 20;       //该竞价组还剩中标数 
    private const int GVShow = 21;       //显示
    private const int GVlassCount = 22;        //该竞价组本次竞价投标人数(低于标底的)

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);

        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {

            prjid = Int32.Parse(SysFun.IsSQL(Request.QueryString["projectid"]));
            showGridView();
        }
        else
        {
            Response.Write("<script>window.alert('对不起,本次竞价您没有竞价品种！');</script>");
            Response.Write("<script>window.location=\"Nothing.aspx?Projectid=" + prjid.ToString() + "\"</script>");
        }
    }

    public void showGridView()
    {
        CP1strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = @"dbo.Bid_goods_product_cs_tb_agent";                                               //要查询的表明
        dbPage.Key = "Bidid";                                               //表的主键    
        dbPage.Where = CP1strConditions;                                           //查询条件    
        dbPage.SelectField = "goodsid,ProductName,Medicinemodel,factor,Outlookc,unit,CompanyName_SC,CompanyName_TB";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 20;                                                    //没有显示记录条数   
        dbPage.OrderBy = "Bidid";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        if (GridView1.Rows.Count < 1) ErrorMsg.Text = "没有满足条件的数据!";//如没有相应数据则提示为无
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }

    public string fctConditions()
    {
        string strtemp;
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
        if (_Account != null)
        {

            CompetepriceAccountid_TBR = SysFun.ToLong(_Account.AccountId);
            strtemp = " AccountID_tb ='" + CompetepriceAccountid_TBR + "' and status=1 AND CheckStatus_goods=1 AND bidid  NOT  IN (SELECT  bidid FROM dbo.CompeteTable) And ProjectId=" + prjid.ToString() + " And";
            //药品通用名

            string CP1PN = SysFun.ToTrim(ProductName.Text);
            if (CP1PN != "")
            {
                strtemp += " ProductName like '%" + CP1PN + "%' And";
            }
            //药品流水号

            string CP1Goodsid = txtGoodsId.Text.Trim();
            if (CP1Goodsid != "")
            {
                strtemp += " Goodsid ='" + CP1Goodsid + "' And";
            }

            //生产企业名称
            string CP1ComSC = CompanyName.Text.Trim();
            if (CP1ComSC != "")
            {
                strtemp += " CompanyName like '%" + CP1ComSC + "%' And";
            }
            //竞价报价
            string _strPriceState = lstPriceState.SelectedValue;
            switch (_strPriceState)
            {
                case "已入围":
                    {
                        strtemp += " isbid=1 And";
                        ErrorMsg.Text = "尊敬的投标人，贵公司投标的下列品规已入围。";
                    }

                    break;
                case "报价低于底价且数量多于理论中标数量":
                    {
                        strtemp += " isbid=0 And";
                        ErrorMsg.Text = "尊敬的投标人，贵公司所投标的下列品规所在竞价组低于底价的报价多于理论中标数量，按照《2009年度云南省药品集中采购工作实施方案》规定，待评标专家给出临床综合评价分，按综合得分确定入围品种后告知最终结果。";
                    }
                    break;

            }

            if (strtemp != "")
            {
                strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
            }
        }
        else
        {
            strtemp = "";

        }
        return strtemp;


    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {


        if (e.Row.RowType == DataControlRowType.DataRow)
        {

        }


    }
}
